package kingiis.utils.projectreader.pop;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import kingiis.utils.projectreader.R;

import static kingiis.utils.simpleapp.utils.Window.backgroundAlpha;

/**
 * Created by King on 2018/2/22.
 */

public class UrlPop {
    static onBtnClickListener mListener;
    public interface onBtnClickListener {
        void onOkClick(String res);

        void onDismiss();
    }


    public static PopupWindow get(final Activity context, onBtnClickListener listener) {
        PopupWindow pop;
        mListener = listener;
        final View view = View.inflate(
                context
                , R.layout.view_showurl
                , null);
        pop = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        pop.setTouchable(true);
        pop.setFocusable(true);
        pop.setAnimationStyle(R.style.PopupAnimation);
        pop.setOutsideTouchable(false);
        pop.setBackgroundDrawable(new BitmapDrawable());
        pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(context, 1f);
                mListener.onDismiss();
            }
        });
        initView(view);
        return pop;

    }

    private static void initView(View view){
        final TextView btn = (TextView)view.findViewById(R.id.submit);
        final EditText str =(EditText) view.findViewById(R.id.url);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onOkClick(str.getText().toString());
            }
        });
    }

}
